import { useLocation, useParams } from 'react-router-dom';

export function useMatchRouteRule() {
  // 获取当前url
  const { pathname } = useLocation();
  // 获取当前路由参数
  const params = useParams();
  // 路由规则
  let routerPath = pathname;

  for (const key in params) {
    const value = params[key];
    if (!value) continue;
    routerPath = pathname.replace(value, `:${key}`);
  }

  return routerPath;
}
